#include "rclcpp/rclcpp.hpp"
#include "base_interfaces_demo/srv/add_ints.hpp"
using base_interfaces_demo::srv::AddInts;
using std::placeholders::_1;
using std::placeholders::_2;
class AddIntsServer:public rclcpp::Node
{
public:
  AddIntsServer():Node("add_ints_server_node_cpp")  
  {
    RCLCPP_INFO(this->get_logger(),"服务节点已创立");
    _service=this->create_service<AddInts>("addints",std::bind(&AddIntsServer::do_service,this,_1,_2));
     RCLCPP_INFO(this->get_logger(),"服务已启动");
  }
  // using CallbackType = std::function<
  //   void (
  //     const std::shared_ptr<typename ServiceT::Request>,
  //     std::shared_ptr<typename ServiceT::Response>)>;
private:
  void do_service(const std::shared_ptr<AddInts::Request> request,std::shared_ptr<AddInts::Response>response)
  {
    response->sum=request->num1+request->num2;
    RCLCPP_INFO(this->get_logger(),"响应的结果为：%d+%d=%d",request->num1,request->num2,response->sum);
  }
  rclcpp::Service<AddInts>::SharedPtr _service; 
};

int main(int argc,char*argv[])
{
    rclcpp::init(argc,argv);
    rclcpp::spin(std::make_shared<AddIntsServer>());
    rclcpp::shutdown();
    return 0;
}